<?php

class DirectoryClass
{
	private function init()
	{
		$this->model = Model::factory('directory');
	}

//	public function validateItem($item)
//	{
//		$this->init();
//		if (($original = $this->model->getItem($item['id'], $item['section']))) {
//			$item = array(
//				'id'		=> $item['id'],
//				'section'	=> $item['section'],
//				'price' 	=> $original['price'],
//				'name'		=> $original['name'],
//			);
//			return $item;
//		}
//		return false;
//	}
	public function validateItem($item)
	{
		$this->init();
		if (($original = $this->model->getItem($item['itemId'], $item['section']))) {
			$item = array(
				'id'		=> $item['itemId'],
                                'attachmentId'  => $item['attachmentId'],
				'section'	=> $item['section'],
				'price' 	=> $original['price'],
				'name'		=> $original['name'],
                                'quantity'      => $item['quantity']
			);
			return $item;
		}
		return false;
	}
	public function validateAttacmentItem($item)
	{
		$this->init();
                $attachment = $this->model->getAttachmentById($item['attachmentId']);
		if ($item['itemId'] == $attachment['itemId']) {
                        $parent = $this->model->getItem($attachment['itemId'], $attachment['section']);
			$item = array(
				'itemId'	=> $parent['id'],
                                'attachmentId'  => $attachment['id'],
				'section'	=> $parent['section'],
				'price' 	=> $parent['price'],
                                'delivery'      => $item['delivery'],
                                'deliveryCost'  => $item['deliveryCost'],
				'name'		=> $parent['name'],
			);
			return $item;
		}
		return false;
	}
	public function validateCustomItem($item)
	{
                $item = array(
                        'id'	=> null,
                        'attachmentId'  => null,
                        'section'	=> null,
                        'price' 	=> 0,
                        'name'		=> 'Custom',
                        'quantity'      => $item['quantity']
                );
                return $item;
	}

	public function setPaid($item)
	{
		return true;
	}

	public function moveFile($file, $type, $sizes)
	{
	}
}
?>